/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cf.controller;

import com.cf.dao.impl.TbPalabraDao;
import com.cf.modelo.TbPalabra;
import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

;

/**
 *
 * @author Soltecn2
 */
@ManagedBean
@SessionScoped
public class TbPalabraController implements Serializable {

    private static final long serialVersionUID = 1L;
    private TbPalabra palabrabean;
    private TbPalabra selectPalabra;
    public List<TbPalabra> listpalabras;
public Integer cboClasificacion;

    public Integer getCboClasificacion() {
        return cboClasificacion;
    }

    public void setCboClasificacion(Integer cboClasificacion) {
        this.cboClasificacion = cboClasificacion;
    }
//    public String redire() {
//
//        TbPalabraDao palabradao = new TbPalabraDao();
//        
//        System.out.println("----------REEEE-"+selectPalabra.getImagen()+" "+selectPalabra.getImagen());
//        palabradao.actualizar(selectPalabra.getImagen(),selectPalabra.getImagen(),1,1);
//        return "wFrmEjercicioCFActualizar";
//    }

    public TbPalabraController() {

        palabrabean = new TbPalabra();
        selectPalabra = new TbPalabra();
        listpalabras=new ArrayList<TbPalabra>();
    }

    public TbPalabra getSelectPalabra() {
        return selectPalabra;
    }

    public void setSelectPalabra(TbPalabra selectPalabra) {
        this.selectPalabra = selectPalabra;
    }

    public TbPalabra getPalabrabean() {
        return palabrabean;
    }

    public void setPalabrabean(TbPalabra palabrabean) {
        this.palabrabean = palabrabean;
    }

//    public String RealizarBusqueda() {
//
//        listpalabras = TbPalabraDao.listPalabras(palabrabean);
//
//        return null;
//    }
//
//    public List<TbPalabra> getListpalabras() {
//        listpalabras = TbPalabraDao.listPalabras(palabrabean);
//        return listpalabras;
//    }

    public void setListpalabras(List<TbPalabra> listpalabras) {
        this.listpalabras = listpalabras;
    }

    public StreamedContent getBytesToStreamedContent() {
        if (FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            StreamedContent image; // So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
            image = new DefaultStreamedContent();
            return image;
        } else {
            String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("imageName");
            InputStream is = new ByteArrayInputStream(id.getBytes());
            StreamedContent image = new DefaultStreamedContent(is, "image/jpeg");
            return image;
        }

    }
}
